﻿Imports System.Xml
Public Class frmConfig

    Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
        Me.Dispose()
    End Sub

    Private Sub btnDataPosition_Click(sender As System.Object, e As System.EventArgs) Handles btnDataPosition.Click
        OpenFileDlg.ShowDialog()
    End Sub

    Private Sub OpenFileDlg_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDlg.FileOk
        txtDataPosition.Text = OpenFileDlg.FileName
        txtDataPosition.SelectionStart = txtDataPosition.TextLength
    End Sub

    Private Sub btnBackupPosition_Click(sender As System.Object, e As System.EventArgs) Handles btnBackupPosition.Click
        If FolderBrowserDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
            txtBackupPosition.Text = FolderBrowserDlg.SelectedPath
        Else
            Exit Sub
        End If
    End Sub

    Private Sub frmConfig_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Call gSubLoadConfig()
        txtOCompany.Text = gOCompNm
        txtOCompNo.Text = gOCompNo
        txtOAddr1.Text = gOAddr1
        txtOAddr2.Text = gOAddr2
        txtOOwner.Text = gOOwner
        txtOTypes.Text = gOTypes
        txtOArticle.Text = gOArticle
        txtOMajor.Text = gOMajor
        txtOPhone.Text = gOPhone
        txtOFax.Text = gOFax
        txtOEmail.Text = gOEmail

        txtBackupPosition.Text = gBackupDir
        txtBackupPosition.SelectionStart = txtBackupPosition.TextLength
        FolderBrowserDlg.SelectedPath = gBackupDir
        txtDataPosition.Text = gDataFile
        txtDataPosition.SelectionStart = txtDataPosition.TextLength
        txtBackupTerms.Text = gBackupTerms
    End Sub

    Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
        Call mkConfig()
    End Sub

#Region "프로시져"

    Private Sub mkConfig()
        Dim writer As New XmlTextWriter(Application.StartupPath + "/config.xml", System.Text.Encoding.UTF8)

        writer.WriteStartDocument(True)
        writer.Formatting = Formatting.Indented
        writer.Indentation = 2
        writer.WriteStartElement("Config")

        writer.WriteStartElement("Company")

        writer.WriteStartElement("compNm")
        writer.WriteString(txtOCompany.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("compNo")
        writer.WriteString(txtOCompNo.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("owner")
        writer.WriteString(txtOOwner.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("addr1")
        writer.WriteString(txtOAddr1.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("addr2")
        writer.WriteString(txtOAddr2.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("types")
        writer.WriteString(txtOTypes.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("article")
        writer.WriteString(txtOArticle.Text)
        writer.WriteEndElement()

        writer.WriteEndElement()

        writer.WriteStartElement("Additional")

        writer.WriteStartElement("phone")
        writer.WriteString(txtOPhone.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("fax")
        writer.WriteString(txtOFax.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("major")
        writer.WriteString(txtOMajor.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("email")
        writer.WriteString(txtOEmail.Text)
        writer.WriteEndElement()

        writer.WriteEndElement()

        writer.WriteStartElement("System")

        writer.WriteStartElement("sourceData")
        writer.WriteString(txtDataPosition.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("backupPosition")
        writer.WriteString(txtBackupPosition.Text)
        writer.WriteEndElement()

        writer.WriteStartElement("backupTerms")
        writer.WriteString(txtBackupTerms.Text)
        writer.WriteEndElement()

        writer.WriteEndElement()
        writer.WriteEndDocument()
        writer.Close()

        MsgBox("환경설정 저장이 완료 되었습니다")
        Call gSubLoadConfig()
    End Sub

#End Region

End Class